package com.dbz.service.Impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dbz.dao.UserDao;
import com.dbz.entity.User;
import com.dbz.entity.UserRoles;
import com.dbz.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
@Service
public class UserServiceImpl  extends ServiceImpl<UserDao, User> implements UserService  {

    @Resource
    private UserDao userDao;
    @Override
    public List<User> selectUser() {
        return userDao.selectList(null);
    }

    @Override
    public User getUserByName(String userName) {
        return userDao.getUserByName(userName);
    }

    @Override
    public String getById(String userName, String password) {
        return userDao.getById(userName,password);
    }

    /**
     * 根据id修改用户信息
     * @param user
     * @return
     */
    @Override
    public int updateRoleById(User user) {
        userDao.updateById(user);
        return 1;
    }
    /**
     * 根据id删除用户信息
     * @param uid
     * @return
     */
    @Override
    public int deleteUserById(String uid) {
        userDao.deleteById(uid);
        return 1;
    }

    /**
     * 添加信息
     * @param user
     * @return
     */
    @Override
    public int userAdd(User user) {
        userDao.insert(user);
        return 1;
    }

    /**
     * 查询所有
     * @return
     */
    @Override
    public List<User> getAll() {
        return userDao.selectList(null);
    }

    @Override
    public IPage<User> selectPage(IPage<User> page, Wrapper<User> queryMapper){
        return userDao.selectPage(page,queryMapper);
    }


    @Override
    public User selectUserById(String uid) {
        return userDao.selectById(uid);
    }

    @Override
    public int delUserRolesByUidAndRid(String uid, String rid) {
        return userDao.delUserRolesByUidAndRid(uid,rid);
    }


}
